home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15629 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.8 KB  |  53 lines

  1. Path: newsbf02.news.aol.com!not-for-mail
  2. From: lennyl9150@aol.com (LennyL9150)
  3. Newsgroups: comp.lang.c
  4. Subject: Array initialization problem
  5. Date: 20 Apr 1996 11:08:03 -0400
  6. Organization: America Online, Inc. (1-800-827-6364)
  7. Sender: root@newsbf02.news.aol.com
  8. Message-ID: <4laukj$q4t@newsbf02.news.aol.com>
  9. Reply-To: lennyl9150@aol.com (LennyL9150)
  10. NNTP-Posting-Host: newsbf02.mail.aol.com
  11.  
  12.  Hi all.  I have a problem initializing an array in a function that has an
  13. array size passed from another function.  OK, before I get you more
  14. confused that's what my program does.  It reads a data file, and puts the
  15. data in the link list.  It also keeps track of how many elements are in
  16. this linked list.  Then at some point I have a function that will process
  17. the data but it needs to have an array (actually more than one array) to
  18. do that.  But when I call such a function with a value of number of
  19. elements in the linked list and try to declare an array to be the size of
  20. this number, Turbo C compiler gives an error saying that array's size must
  21. be a constant.  I tried to cast it as a constant but it didn't work.   So
  22. I searched my books on C and one did mention this problem, but did not
  23. give any suggestions.  Below is a simple pseudocode in case I got you all
  24. confussed.
  25.  
  26. main()
  27. {
  28.     int cnt = 0;
  29.     while (fscanf()) {
  30.         create_link();
  31.         ++cnt;
  32.      } /* end while */
  33.  
  34.     make_matrix( cnt );
  35. }
  36.  
  37. void make_matrix(int size)
  38. {
  39.     int arr[size];  /* This is where compiler complains that size has to
  40. be a constant
  41.                            I tried casting but it did not help. */
  42. }
  43.  
  44. Any sugestions are appreciatted.  Thank you very much.
  45. Lenny
  46.  
  47.  
  48. This is Lenny reporting from the Sunshine State:
  49. "Today, once again, we have a 100% chance of showers and possible
  50. thunderstorms."
  51.  
  52. lennyl9150@aol.com   or   lleyze@unf.edu
  53.